;$(function(){
	
	//form表单校验
	$('#form').validate({
		rules:{
			loginName: {
				required:true,
				maxlength: 20
			},
			password: {
				required: true
			}
		},
		messages:{
			loginName: {
				required: '请填写账号',
				maxlength: '最多输入20个字符'
			},
			password: {
				required: '请填写密码'
			}
		},
        submitHandler:function(form){
			
			var loginName = $('#formId').val();
			
			if(loginName != '') {
				update();
			} else {
				add();
			}
			
        	return false;
        }
	});
	
	function update() {		
		var data = $('#form').serializeJson();
		$.request({
			type: 'post',
			url: 'user/update',
			data: JSON.stringify(data),
			closeTop: true,
			msg: '修改成功'
		});
	}
	
	function add() {
		var data = $('#form').serializeJson();
		$.request({
			type: 'post',
			url: 'user/add',
			data: JSON.stringify(data),
			closeTop: true,
			msg: '添加成功'
		});
	}
	
	
	
} );